package com.two.screen.water.balance.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

/**
 * 创建者     Noel
 * 创建时间   2019/5/24 11:57
 * 描述	      ${TODO}
 */
public class EqualWidthHalfHeightRelativeLayout extends RelativeLayout {
    public EqualWidthHalfHeightRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public EqualWidthHalfHeightRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public EqualWidthHalfHeightRelativeLayout(Context context) {
        super(context);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(getDefaultSize(0, widthMeasureSpec),
                getDefaultSize(0, heightMeasureSpec));

        int childWidthSize = getMeasuredWidth();
        //int childHeightSize = (int) (childWidthSize * 1.2 + 0.5);
        // 高度和宽度一样
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize / 2, MeasureSpec.EXACTLY);
        //heightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);
        // widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);

        System.out.println("图片宽高==>heightMeasureSpec:" + heightMeasureSpec + ",widthMeasureSpec:" + widthMeasureSpec + ",childWidthSize:" + childWidthSize);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}
